<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<title>白名单管理</title>
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
	<%@ include file="uct-import.jsp" %>
	
	<script>
	
	    var add_url  = 'unlock!save.action';
	    var del_url  = 'unlock!delete.action';
	    var get_url  = 'unlock!get.action';
	    var page_url = 'unlock!data.action';
	
	    //easyUI分页列表
		$(function(){
			$('#pageList').datagrid({
			singleSelect:(this.value==1),
				toolbar:[					
		          {		        	  
		              text:'增加',
			          iconCls:'icon-add',
			          handler:function(){
					  //打开窗口
			          $('#win').window('open');
			          }
		          },'-', 
		          {
		              text:'删除',
		              iconCls:'icon-cut',
		              handler:function(){
		                 var objs = $('#pageList').datagrid('getSelections');
		                 if (objs == null || objs == '') {
                             $.messager.alert('提示消息', '请选择要删除的数据！', 'info');
                         } else {
                         	 $.messager.confirm('确认','确定要删除所选数据吗?',function(flag){ 
	                             var ids="";
		                         if(flag){
			                         $.each(objs,function(i,n){   
			                             ids=ids+",'"+n.id+"'";
			                         });
			                         del(ids);
	                             }
		                     });  
                         }
                      }      
		          },'-',
		          {
		              text:'修改',
		              iconCls:'icon-edit',
		              handler:function(){
	                     var objs = $('#pageList').datagrid('getSelected');
	                     var length = $('#pageList').datagrid('getSelections').length;
	                     
		                 if (objs == null || objs == '') {
                             $.messager.alert('提示消息', '请选择要修改的数据！', 'info');
                         } 
                         else if(length>1){
                             $.messager.alert('提示消息', '请选择一条数据进行修改！', 'info');
                         }
                         else {
                         	 var sid=objs.id;
                         	 var name=objs.unlockCname;
                             preUpdate(sid,name);
                         }
                      }   
		          }
		          ,'-',		         
		           {
		              text:'刷新',
		              iconCls:'icon-reload',
		              handler:function(){
		                  load();
		             }
		          }
		        ],
		         onLoadSuccess:function(){   
                 	$('#pageList').datagrid('clearSelections'); 
                 },
                 onDblClickRow:function()//双击如果复选框选中则取消
                 {
                     var objs = $('#pageList').datagrid('getSelected');
                      if (objs != null || objs != '') {
                     	 $('#pageList').datagrid('clearSelections'); 
                      }
                 }
		    });
		});
		
	//刷新方法：刷新分页列表
	function load(){
		$('#pageList').datagrid('reload');
	}
		
		
	//保存方法
	function save(){
	  $('#inputForm').form('submit', {
		    url:add_url,
		    onSubmit:function(){
		        return $(this).form('validate');
		    },
		    success:function(data){
		    	var oTxt = jQuery.parseJSON(data);
				var mess = oTxt.message;
				var flag = oTxt.flag;
				
				$.messager.alert('提交结果',mess, 'info',function(){
			        if(flag=='true'){
			        	load();
			        	$('#win').window('close');
			        	//$('#inputForm').form('clear');
			        	//当修改保存后去掉id隐藏框，
			        	//否则后台处理save的时候抛entity为空异常。
			        	$("#id").remove();
			        	$('#unlockEname').removeAttr('readonly');
			        	$('#unlockStatus').val('1');
			        }
		        });
		    }
		});
     }
     
      //删除方法
	 function del(ids){
        $.ajax({
		  url: del_url,
		  type: 'POST',
		  cache: false,
		  data: 'ids='+ids,
		  success: function(data){
		  	var oTxt = jQuery.parseJSON(data);
		    var mess = oTxt.message;	
			var flag = oTxt.flag;
	        $.messager.alert('删除结果',mess, 'info');
	        if(flag){
	        	load();
	        	// $('#inputForm').form('clear');
	        }
		  }
	    });
     }
      
      //预修改确认
    function preUpdate(sid,name){
	  //$.messager.confirm('确认','确定要: <font color=red>'+name+'</font> 的相关信息吗?',function(flag){  
	      // if(flag){  
	           preUpdateData(sid);
	       //}  
	  //});
    }
    
    //提取预修改数据
    function preUpdateData(id){
		$('#inputForm').form('load',get_url+'?id='+id+'&r='+(new Date()).getTime());
		$('#inputForm').append('<input type=hidden id=id name=id value='+id+'>');
		$('#unlockEname').attr('readonly','readonly');
		//打开窗口
		$('#win').window('open');
    }
    
    //查询
    function searchList(){					
	    	var queryParams = $('#pageList').datagrid('options').queryParams;	
	    	//查询条件放到queryParams中：格式filter_params       
	        queryParams.filter_unlockEname = $('#unlockEnameSearch').val();
	        queryParams.filter_unlockCname = $('#unlockCnameSearch').val();
	        var options = $('#pageList').datagrid('getPager').data("pagination").options;  
	        options.pageNumber=1;  
	        options.total=0;  
	        options.pageSize=10; 
	        $('#pageList').datagrid("reload");
       	}
       	
    //清空查询条件   
    function clearForm(){   
      	$('#pageList'). datagrid('clearSelections');  
	    $('#queryForm')[0].reset();  
   } 
   
    function goBack(){
	   	$('#pageList'). datagrid('clearSelections');  
	    $('#inputForm')[0].reset();  
	    $('#id').remove();
	    $('#unlockEname').removeAttr('readonly');
	   	$('#win').window('close');  
   } 
</script>
</head>
<body>
	<form id="queryForm" name="queryForm">
			<table class="datagrid-body">
			<tr>
				<td class="datagrid-header">
					白名单英文名称
				</td>
				<td>
					<input type="text" id="unlockEnameSearch" name="unlockEname" size="20" value="" />
				</td>
				<td class="datagrid-header">
					白名单中文名称
				</td>
				<td>
					<input type="text" id="unlockCnameSearch" name="unlockCname" size="20" value="" />
				</td>
				<td>
			    <a href="#" onclick="searchList();" class="easyui-linkbutton" iconCls="icon-search">查询</a>
			    <a href="#" onclick="clearForm();" class="easyui-linkbutton" iconCls="icon-search">清空</a>
				</td>
			</tr>
		</table>
	</form>
	<!-- 分页列表 -->
    <table id="pageList" class="easyui-datagrid" title="白名单列表"  data-options="rownumbers:true,singleSelect:true,pagination:true,url:page_url">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true,width:2,
				
				"/>
				<th data-options="field:'unlockEname',width:120,
					sorter:function(a,b){
							return (a>b?1:-1);
						}">白名单英文名称</th>
				<th data-options="field:'unlockCname',width:120,
					sorter:function(a,b){
							return (a>b?1:-1);
						}">白名单中文名称</th>
				<th data-options="field:'unlockStatus',width:80,
					sorter:function(a,b){
							return (a>b?1:-1);
						},
					formatter:function(value){
							if( value=='1'){
								return '<font color=blue>启用</font>';
							}else if(value=='0'){ 
								return '<font color=red>停用</font>';
							}else{
								return '';
							}
						}
					">白名单状态</th>
				<th data-options="field:'unlockPath',width:400,
					sorter:function(a,b){
							return (a>b?1:-1);
						}
				">白名单路径</th>
				<th data-options="field:'unlockRemark',width:270,
					sorter:function(a,b){
							return (a>b?1:-1);
						}
					">白名单描述</th>
			</tr>
		</thead>
	</table>
    
    <!-- 增加修改表格 -->
	<div id="win" class="easyui-window" title="白名单管理" style="padding: 5px; width: 600px; height: 400;"
		 iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
		  <form id="inputForm" action="" method="post">
			<table class="datagrid-body">
			  <tr><td>白名单英文名<span style="color: red;">*</span></td><td>
			     <input class="easyui-validatebox" type="text"  
											      id="unlockEname"  name="unlockEname"   
											      value="${entity.unlockEname}"   
											      size="65" 
											      data-options="required:true,validType:'english'">
			                         </td>
			  </tr>
			  <tr><td>白名单中文名<span style="color: red;">*</span></td><td><input class="easyui-validatebox"
			                                    type="text" 
			                                    id="unlockCname" 
			                                    name="unlockCname" 
			                                    value="${entity.unlockCname}"
			                                    size="65"
			                                    data-options="required:true"></td></tr>
			  <tr><td>白名单路径 <span style="color: red;">*</span></td><td><input class="easyui-validatebox"
			                                precision="0"
			                                type="text" 
			                                id="unlockPath" 
			                                name="unlockPath" 
			                                value="${entity.unlockPath}"
			                                size="65"
			                                data-options="required:true">
			                                </td></tr>
			  <tr><td>白名单状态<span style="color: red;">*</span></td><td>
			   <select id="unlockStatus" name="unlockStatus">
			       <option value="1" <c:if test="${entity.unlockStatus=='1'}">selected</c:if>>启用</option>
			       <option value="0" <c:if test="${entity.unlockStatus=='0'}">selected</c:if>>停用</option>
			   </select></td></tr>
			                               
			   <tr><td>白名单描述</td><td>
			   <textarea id="unlockRemark" name="unlockRemark" rows="5" cols="54">${entity.unlockRemark}</textarea>
			   </td></tr>
			   
			  <tr>
				  <td colspan="2">
				      <a href="#" onclick="save();" class="easyui-linkbutton" iconCls="icon-save">提交</a>
				  </td>
			  </tr>
			</table>
			</form>
</div>
</body>
</html>